define(function(require){
	var $=require("jq");
	var Dialog=require("pz_use_dialog.js");
	
	$.fn.checkNewPwd = function(){
		var pwd = (/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/);
		var items = new Array("!","@","#","$","%","^","&","*","(",")","_","-","+","=","<",">","?",";",":","'","~");
		if($(this).val()==""){
			$(this).next().html("请输入密码！").show().removeClass("ok").addClass("tips");
			return false;
		}else if(!pwd.test($(this).val())){
			$(this).next().html("密码必须是字母和数字组合！").show().removeClass("ok").addClass("tips");
			return false;
		}else if($(this).val().length < 6){
			$(this).next().html("密码至少6位！").show().removeClass("ok").addClass("tips");
			return false;
		}else{
			for(var i=0;i<items.length;i++){
				if($(this).val().indexOf(items[i]) >= 0){
					$(this).next().html("密码包含特殊字符！").show().removeClass("ok").addClass("tips");
					return false;
				}
			}
			$(this).next().html("").show().removeClass("tips").addClass("ok");
			return true;
		}
	}
	$.fn.checkConfirmPwd = function(){
		var new_pwd = $('#newPassword').val();
		if($(this).val()==""){
			$(this).next().html("请输入确认密码！").show().removeClass("ok").addClass("tips");
			return false;
		}else if(new_pwd != $(this).val()){
			$(this).next().html("密码与确认密码不一致！").show().removeClass("ok").addClass("tips");
			return false;
		}else{
			$(this).next().html("").show().removeClass("tips").addClass("ok");
			return true;
		}
	}
	$('#newPassword').blur(function(event) {
		$(this).checkNewPwd();
	});
	$('#Password').blur(function(event) {
		$(this).checkConfirmPwd();
	});
	
	
	$('#submit').on('click',function(event){
		if(!$('#newPassword').checkNewPwd()){
			return;
		}
		if(!$('#Password').checkConfirmPwd()){
			return;
		}
		
		var password = $('#newPassword').val();
		var password2 = $('#Password').val();
		var params = {};
		params['newPassword'] = password;
		params['Password'] = password2;
		$.post("/vipCenter/setPayPasswordOK.do",params,function(data){
			var result = eval("("+data+")");
			if(result['ok'] == 1){
				window.location.href=result['url'];
				return;
			}else if(result['ok'] == 0){
				alert(result['msg']);
				$('#newPassword').val('');
				$('#Password').val('');
				return;
			}
		});
	});
});